package day15;

import java.util.*;

public class Demo {
    public static void main(String[] args) {
        String str = "Hello World How are you Im fine and you Im ok";
        Map<String , Integer> map = new HashMap<>();//key排序
        for (String word : str.split(" ")){
            if (map.containsKey(word)){
                map.put(word, map.get(word)+1);
            }
            else {
                map.put(word, 1);
            }
        }
        System.out.println(map);
        List<Map.Entry<String, Integer>> list = new ArrayList<>(map.entrySet());
        Collections.sort(list,(o1, o2) -> o2.getValue().compareTo(o1.getValue()));
        System.out.println(list);
    }
}
